/**
 * Created by Administrator on 2017/7/17.
 */
var gamestart, mu01, gameTis, text_left_1, text_left_2, text2_2, text2_4,answer;
var ans=['向天再借五百万','给你三万要不要','有钱任性没钱认命','五行缺钱','专业让贷款更简单'];
var result;
var count=0;
var index = [], look, restart;
var musicimg, musicDing, musicnext;
var math;
window.onload = function () {
    gamestart = document.getElementById('start');
    mu01 = document.getElementById('mu01');
    musicDing = document.getElementById('musicDing');
    musicnext = document.getElementById('musicnext');
    restart = document.getElementById('restart');
    look = document.getElementsByClassName('look');
    musicimg = document.getElementsByClassName('musicimg');
    gameTis = document.getElementsByClassName('gameTis');
    text_left_1 = document.getElementsByClassName('text_left_1');
    text_left_2 = document.getElementsByClassName('text_left_2');
    text2_2 = document.getElementsByClassName('text2_2');
    text2_4 = document.getElementsByClassName('text2_4');
    answer = document.getElementsByClassName('answer');
    result = document.getElementsByClassName('result');
    math = document.getElementById('math');
    for (let i = 0; i < look.length; i++) {
        look[i].onclick = function () {
            index[6 + i].style.display = 'none';
            index[7 + i].style.display = 'block';
        }
    }
    restart.onclick = function () {
        location.replace(location.href);
    }
    for (let i = 0; i < 5; i++) {
        musicimg[i].onclick = function () {
            for (let game = 0; game < gameTis.length; game++) {
                gameTis[game].style.visibility = 'hidden'
            }
            musicDing.play();
            setTimeout(function () {
                mu01.src = `img/sounds/mu0${i + 1}.mp3`;
                mu01.load();
                mu01.play();
            }, 1500);

        };
    }
    console.log(text2_2.length)
    for (let i = 0; i < 5; i++) {
        text2_2[i].onclick = function () {
            musicnext.load();
            musicnext.play();
            text_left_1[i].style.animation = 'left 1s linear ';
            text_left_2[i].style.animation = 'left_2 1s linear ';
            console.log(answer[i].value);
            if(answer[i].value == ans[i]) {
                result[i].src = 'img/game_right.png';
                count++;
                math.innerText=count*20+'分';
            }
            text_left_1[i].addEventListener('webkitAnimationEnd', function () {
                index[i + 1].style.display = 'none';
                index[i + 2].style.display = 'block';
            });
        }

        text2_4[i].onclick = function () {
            musicnext.load();
            musicnext.play();
            text_left_1[i].style.animation = 'left 1s linear ';
            text_left_2[i].style.animation = 'left_2 1s linear ';
            text_left_1[i].addEventListener('webkitAnimationEnd', function () {
                index[i + 1].style.display = 'none';
                index[i + 2].style.display = 'block';
            });
        }
    }
    for (var i = 0; i < 9; i++) {
        index[i] = document.getElementsByClassName('index_' + (i + 1))[0];
    }

    gamestart.onclick = function () {
        index[0].style.display = 'none';
        index[1].style.display = 'block';
    }

}